<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" >
	<meta name="author" content="wangyupeng">
	<title>定制单位卡</title>
	<script language="javascript" src="../script/print.js" type="text/javascript"></script>
	<script language="javascript" src="../script/common.js" type="text/javascript"></script>
	<script language="javascript" src="../script/card.js" type="text/javascript"></script>
	<script language="javascript" src="../script/tree.js" type="text/javascript"></script>
	<!--动态js-->
	<script language="javascript" type="text/javascript">
	//页面加载方法
	var qt;	
	var companyUser;
	var resultData;
	var cOrg;
	function load(){
		Eui.showNavigation();
		setPages(["mainview","readcardview","createcompanydiv","createdeptdiv","detview"]);
		cOrg = Common.cOrg();
	}
	
	//刷新未发卡司机列表
	function refreshTable(){
		CardMgnt.drivers.qt.showTable();
	}
	//读主卡，查找单位客户帐户
	function readMasterCard(){
		try{getCard();}catch(e){showError(e.description);return;}
		var asn = getAsn();
		companyform.asn.value = asn;
		DWR.call("mgntQueryService.findOkCompanyUser",asn,null,showCompanyUser)
	}
	
	//通过客户编号查找单位客户帐户
	function findCompanyUser(){
		DWR.call("mgntQueryService.findOkCompanyUser",null,companyform.uniqueId.value,showCompanyUser)
	}
	
	//选择客户编号编号
	function selCardUser(){
		CardMgnt.selCardUser(function(v){
			companyform.uniqueId.value = v.uniqueId;
		},{cardUserType:CardUserType.COMPANY})
	}
	//显示单位客户信息
	function showCompanyUser(data){
		resultData = data;
		companyUser = data.cardUser;
	
		if (!CardMgnt.checkCompanyLocation(companyUser)) return;
		
		switchPage("readcardview");
		Common.setValues(companyUserViewForm,CardMgnt.parseCardUser(data));
		
		var fee = CardMgnt.getFee(Constants.ACCOUNT_FEE_CUSTOMIXE_CARD,data.userCardType.id);
		var foregift = CardMgnt.getFee(Constants.ACCOUNT_FOREGIFT_CARD,data.userCardType.id);
		companyUserViewForm.feeAmount.value = Format.fenToYuan(fee);
		companyUserViewForm.foregiftAmount.value = Format.fenToYuan(foregift);
		
		var options = {}
		options.status = CardUserStatus.UNACTIVATED;
		options.displayColumns = [0,1,2,3,4,8]
		CardMgnt.drivers.showList("driversdiv",companyUser.id,null,options)
	}
	
	//创建单位
	function createCompany(){
		switchPage("createcompanydiv");
		CardMgnt.customer.show("companycustomerdiv",null,CardMgnt.COMPANYALL,{isCreate:true});
		CardMgnt.cardUser.show("companyuserdiv",null,CardMgnt.COMPANYALL);
	}
	
	//保存单位客户帐户
	function saveCompany(){
		if (!checkForm(CardMgnt.customer.formName)) return;
		if (!checkForm(CardMgnt.cardUser.formName)) return;
		var cc = CardMgnt.customer.get();
		if (!cc.checkIdno){
			var c = DWR.syncCall("customerService.getCompanyCustomerForCardUser",cc.idno,cc.idnoType);
			if (c){
				if (!showQuestion("档案已经存在，是否在该档案下继续创建客户资料？")){onCancel();return;}
				cc.id = c.id
			}
		}
		var cu = CardMgnt.cardUser.get();
		DWR.call("customerService.saveCompanyCustomerAndUser",cc,cu,function(result){
			showInformation("单位客户保存成功");
			resultData = result;
			//TODO 打印单位建档凭证
			if (showQuestion("是否创建单位部门？")){
				createDept()
			}else
				showCompanyUser(resultData);
		},{blockScreen:true});
	}
	
	function createDept(){
		switchPage("createdeptdiv");
		CardMgnt.dept.showData("dept_tree_view",resultData);
	}
	function editDeptFinish(){
		showCompanyUser(resultData);
	}
	//定制选中的司机
	function customizeDriver(){
		var ids = CardMgnt.drivers.qt.getBoxValue();
		if (!ids){showWarning("请选择定制的司机！");return;}
		var cardAmount = ids.split(",").length;
		if (!showQuestion("是否定制"+cardAmount+"张单位卡？")) return;
		DWR.call("cardMgntService.customizeCompanyCard",ids,function(data){
			showInformation("单位卡定制成功");
			switchPage("detview");
			CardMgnt.showPrintView("detview","customize_company_bill",data.logId,"定制卡片凭证");
			try{WebPrint.print('billview');}catch(e){showWarning("打印出错："+e.description);return;}
		},{blockScreen:true});
	}
	
	//重置
	function onCancel(){
		switchPage("mainview");
		companyUser = null;
		Common.setValues(companyUserViewForm,{});
		companyform.reset();
	}
	
	//返回
	function back(){
		switchPage("readcardview");
		refreshTable();
	}
	</script>
</head>
<body onload="load()">
	<!--页面导航-->
	<div class="nav"><div id="nav">&nbsp;</div></div>
	<div id="mainview">
		<div class="form">
			<form id="companyform" name="companyform">
				<div class="formTitle"><div class="l">查询单位客户</div><div class="r">
					<div style="margin-top:4px;margin-right:20px;"><a href="#" onclick="createCompany()">新建单位客户</a></div>
				</div></div>
				<table cellSpacing=0 cellPadding=4 width="100%" border=0 class="label4">
					<tr>
						<td>
							<label>单位主卡</label> <input type="text" name="asn" readonly class="readonly">
							<button onclick="readMasterCard()">读主卡</button>
						</td>
						<td>
							<label>客户编号</label> <input type="text" name="uniqueId"><a class="orga" href="#" onclick="selCardUser()">&nbsp;&nbsp;</a>
						</td>
						<td>
							<button onclick="findCompanyUser()">查 询</button>
						</td>
					</tr>	
				</table>
			</form>
		</div>
	</div>
	<div id="readcardview" style="display:none;">
		<div class="form">
			<div class="formTitle">单位帐号信息</div>
			<form id="companyUserViewForm" name="companyUserViewForm">
				<input type="hidden" name="cardType">
				<table cellSpacing="0" cellPadding="4" width="100%" border="0" class="col4 label4">
					<tr>
						<td><label>单位名称</label> <input name="name" type="text" readonly class="readonly"></td>
						<td><label>证件类型</label> <input name="idnoTypeText" type="text" readonly class="readonly"></td>
						<td><label>证&nbsp;件&nbsp;号</label> <input name="idno" type="text" readonly class="readonly"></td>
					</tr>
					<tr>
						<td><label>客户编号</label> <input name="uniqueId" type="text" readonly class="readonly"></td>
						<td><label>开户机构</label> <input name="buildFileStationName" type="text" readonly class="readonly"></td>
						<td><label>状&nbsp;&nbsp;&nbsp;&nbsp;态</label> <input name="statusText" type="text" readonly class="readonly"></td>
					</tr>
					<tr>
						<td><label>卡片类型</label> <input name="cardTypeName" type="text" readonly class="readonly"></td>
						<td><label>押 金</label> <input name="foregiftAmount" type="text" readonly class="readonly">元/张</td>
						<td><label>手续费</label> <input name="feeAmount" type="text" readonly class="readonly">元/张</td>
					</tr>
				</table>
			</form>
		</div>
		<div id='tabsdiv' align="left" class="width97"></div>
		<div id="driversdiv" style="margin-top:-10px;">
		</div>
		<div id="deptsdiv" style="display:none;" class="width97">
			<iframe id="deptframe" name="deptframe" style="width:100%;height:340px;overflow:hidden" scrolling="no" frameborder=0 src=""></iframe>
		</div>
		
		<div id="limitview" style="display:none;" class="width97">
			<iframe id="limitframe" name="limitframe" style="width:100%;height:340px;overflow:hidden" scrolling="no" frameborder=0 src=""></iframe>
		</div>
		<p>
			<button id="customizeCompanyBtn" onclick="customizeDriver()">定制卡片</button>
			<button onclick="onCancel()">返 回</button>
		</p>
	</div>
	<div id="createcompanydiv" style="display:none;">
		<div id="companycustomerdiv" class="form">
		</div>
		<div id="companyuserdiv" class="form">
		</div>
		<p>
			<button onclick="saveCompany()">保 存</button>
			<button onclick="onCancel()">取 消</button>
		</p>
	</div>
	<div id="createdeptdiv" style="display:none;">
		<div id="dept_tree_view">
		</div>
		<p>
			<button onclick="editDeptFinish()">部门维护完成</button>
		</p>
	</div>
	<!--售卡明细页面-->
	<div id="detview" style="display:none;">
	</div>
</body>
</html>